import Vue from 'vue'
import Vuex from 'vuex'
import http from '@/util/http'
// 导入持久化模块
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  // 使用持久化保存值
  plugins: [createPersistedState({
    reducer: (state) => {
      return {
        cityId: state.cityId,
        cityName: state.cityName
      }
    }
  })],
  state: {
    cityId: '370800',
    cityName: '济宁',
    cinemaList: [],
    isShow: true
  },
  actions: {
    getCinemaData (store, cityId) {
      http({
        url: `/gateway?cityId=${cityId}&ticketFlag=1&k=4675299`,
        headers: {
          'X-Host': 'mall.film-ticket.cinema.list'
        }
      }).then(res => {
        // console.log(res.data.data.cinemas)
        // this.cinemaslist = res.data.data.cinemas
        store.commit('changeCinemaData', res.data.data.cinemas)
      })
    }
  },
  mutations: {
    changeCityName (state, cityName) {
      state.cityName = cityName
    },
    changeCityId (state, cityId) {
      state.cityId = cityId
    },
    changeCinemaData (state, data) {
      state.cinemaList = data
    },
    clearcinemaList (state) {
      state.cinemaList = []
    },
    hide (state) {
      state.isShow = false
    },
    shown (state) {
      state.isShow = true
    }
  }
})
